m=101;
x=0:10/(m-1):2*pi;
y=cos(x)+x;z=0*x;
plot(x,z,'r',x,y,'LineWidth',1.5),
gtext('y=cos(x)+x'),pause
 
n=3;
x0=-5:10/(n-1):5;
y0=cos(x0)+x0;
y1=lagr1(x0,y0,x);
hold on,plot(x,y1,'b'),gtext('n=2'),pause,
hold off
 
n=5;
x0=-5:10/(n-1):5;
y0=cosx0+x0;
y2=lagr1(x0,y0,x);
hold on,plot(x,y2,'b:'),gtext('n=4'),pause,
hold off
 
n=7;
x0=-5:10/(n-1):5;
y0=cosx0+x0;
y3=lagr1(x0,y0,x);hold on,
plot(x,y3,'r'),gtext('n=6'),pause,
hold off
 
n=9;
x0=-5:10/(n-1):5;
y0=cosx0+x0;
y4=lagr1(x0,y0,x);hold on,
plot(x,y4,'r:'),gtext('n=8'),pause,
hold off
 
n=11;
x0=-5:10/(n-1):5;
y0=cosx0+x0;
y5=lagr1(x0,y0,x);hold on,
plot(x,y5,'m'),gtext('n=10')
 
legend('y=cosx+x','n=2','n=4','n=6','n=8','n=10')

